package com.ruoyi.pressure.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; //添加
import com.ruoyi.pressure.dto.DblcAbnormalDto;
import com.ruoyi.pressure.dto.KyLaneMgylDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.pressure.mapper.KyLaneMgylAbnormalMapper;
import com.ruoyi.pressure.domain.KyLaneMgylAbnormal;
import com.ruoyi.pressure.service.IKyLaneMgylAbnormalService;

/**
 * 错 杆（索）应力测点异常信息数据项说阴Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-06
 */
@Service
public class KyLaneMgylAbnormalServiceImpl extends ServiceImpl<KyLaneMgylAbnormalMapper, KyLaneMgylAbnormal> implements IKyLaneMgylAbnormalService //修改
{
    @Autowired
    private KyLaneMgylAbnormalMapper kyLaneMgylAbnormalMapper;

    /**
     * 查询错 杆（索）应力测点异常信息数据项说阴
     * 
     * @param kyLaneMgylAbnormalId 错 杆（索）应力测点异常信息数据项说阴主键
     * @return 错 杆（索）应力测点异常信息数据项说阴
     */
    @Override
    public KyLaneMgylAbnormal selectKyLaneMgylAbnormalByKyLaneMgylAbnormalId(String kyLaneMgylAbnormalId)
    {
        return kyLaneMgylAbnormalMapper.selectKyLaneMgylAbnormalByKyLaneMgylAbnormalId(kyLaneMgylAbnormalId);
    }

    /**
     * 查询错 杆（索）应力测点异常信息数据项说阴列表
     * 
     * @param kyLaneMgylAbnormal 错 杆（索）应力测点异常信息数据项说阴
     * @return 错 杆（索）应力测点异常信息数据项说阴
     */
    @Override
    public List<KyLaneMgylAbnormal> selectKyLaneMgylAbnormalList(KyLaneMgylAbnormal kyLaneMgylAbnormal)
    {
        return kyLaneMgylAbnormalMapper.selectKyLaneMgylAbnormalList(kyLaneMgylAbnormal);
    }

    /**
     * 新增错 杆（索）应力测点异常信息数据项说阴
     * 
     * @param kyLaneMgylAbnormal 错 杆（索）应力测点异常信息数据项说阴
     * @return 结果
     */
    @Override
    public int insertKyLaneMgylAbnormal(KyLaneMgylAbnormal kyLaneMgylAbnormal)
    {
        return kyLaneMgylAbnormalMapper.insertKyLaneMgylAbnormal(kyLaneMgylAbnormal);
    }

    /**
     * 修改错 杆（索）应力测点异常信息数据项说阴
     * 
     * @param kyLaneMgylAbnormal 错 杆（索）应力测点异常信息数据项说阴
     * @return 结果
     */
    @Override
    public int updateKyLaneMgylAbnormal(KyLaneMgylAbnormal kyLaneMgylAbnormal)
    {
        return kyLaneMgylAbnormalMapper.updateKyLaneMgylAbnormal(kyLaneMgylAbnormal);
    }

    /**
     * 批量删除错 杆（索）应力测点异常信息数据项说阴
     * 
     * @param kyLaneMgylAbnormalIds 需要删除的错 杆（索）应力测点异常信息数据项说阴主键
     * @return 结果
     */
    @Override
    public int deleteKyLaneMgylAbnormalByKyLaneMgylAbnormalIds(String[] kyLaneMgylAbnormalIds)
    {
        return kyLaneMgylAbnormalMapper.deleteKyLaneMgylAbnormalByKyLaneMgylAbnormalIds(kyLaneMgylAbnormalIds);
    }

    /**
     * 删除错 杆（索）应力测点异常信息数据项说阴信息
     * 
     * @param kyLaneMgylAbnormalId 错 杆（索）应力测点异常信息数据项说阴主键
     * @return 结果
     */
    @Override
    public int deleteKyLaneMgylAbnormalByKyLaneMgylAbnormalId(String kyLaneMgylAbnormalId)
    {
        return kyLaneMgylAbnormalMapper.deleteKyLaneMgylAbnormalByKyLaneMgylAbnormalId(kyLaneMgylAbnormalId);
    }

    @Override
    public List<String> getMgylValueList() {
        List<KyLaneMgylDto> list = kyLaneMgylAbnormalMapper.getMgylValueList();
        if (list == null || list.isEmpty()) {
            //list  为空
            List<KyLaneMgylDto> defaultList = new ArrayList<>();
            for (int i = 0; i < 7; i++) {
                KyLaneMgylDto abnormalCountDto = new KyLaneMgylDto();
                abnormalCountDto.setAbnormalCount(0);
                defaultList.add(abnormalCountDto);
            }
            List<String> collect = defaultList.stream().map(objInList -> {
                String abnormalCount = String.valueOf(objInList.getAbnormalCount());
                return abnormalCount;
            }).collect(Collectors.toList());
            return collect;
        } else {
            List<KyLaneMgylDto> resultList = new ArrayList<>(list);
            while (resultList.size() < 7) {
                KyLaneMgylDto abnormalCountDto = new KyLaneMgylDto();
                resultList.add(abnormalCountDto);
            }

            List<String> collect = resultList.stream().map(objInList -> {
                String abnormalCount = String.valueOf(objInList.getAbnormalCount());
                return abnormalCount;
            }).collect(Collectors.toList());
            return collect;
        }
    }
}
